package com.ksm.zyz.common.base;


import com.ksm.zyz.common.util.PropertiesLoader;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 全局变量属性类
 *
 * @author ailot
 */
public class Global {

    public static final String CURRENT_USER = "CURRENT_USER";

    /**
     * 当前实例对象
     */
    private static Global global;

    /**
     * 保存全局属性
     */
    public static Map<String, String> map = Maps.newHashMap();

    /**
     * 属性文件加载对象
     */
    private static PropertiesLoader loader = new PropertiesLoader("system.properties");


    /**
     * 获取当前实例对象
     */
    public static Global getInstance() {
        if(global == null){
            global = new Global();
        }
        return global;
    }

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null) {
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return loader.getProperty(key);
    }

    /*全局信息提示*/
    public static final String SUCCESSFUL = "操作成功";
    public static final String FAILURE = "操作失败";

}
